package com.ticket.serviceImpl;

import com.ticket.dao.IDbDAO;
import com.ticket.exception.ServiceException;
import com.ticket.pojo.FlightSite;
import com.ticket.service.IBaseService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.annotation.Resource;

public class BaseServiceImpl implements IBaseService {
	private static final Log log = LogFactory.getLog(BaseServiceImpl.class);

	@Resource
	public IDbDAO dbDAO = null;

	public Integer deleteFlag = Integer.valueOf(0);

	public String versionFlag = "site";

	public String orderBy = "s.status.createTime desc";

	public String orderValueOrderBy = "s.status.orderValue desc";
	public String orderByOrderValueAsc = "s.status.orderValue asc";

	public void merge(Object object) throws ServiceException {
		try {
			this.dbDAO.merge(object);
		} catch (Exception e) {
			log.info(e.fillInStackTrace());
		}
	}

	public void persist(Object object) throws ServiceException {
		try {
			this.dbDAO.persist(object);
		} catch (Exception e) {
			log.info(e.fillInStackTrace());
		}
	}

	public boolean isInternational(String site) {
		String international = (String) this.dbDAO.executeJPQLForQuerySingle(
				"select t.site from " + FlightSite.class.getName()
						+ " t where t.des=?", String.class,
				new Object[] { site });
		if ("CN".equals(international)) {
			return false;
		}
		return true;
	}
}